home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Add-On
/
Workbench Add-On - Volume 1.iso
/
BBS-Archive
/
Dev
/
Obrn-A_1.6_lib.lha
/
oberon-a
/
source3.lha
/
source
/
EAGUI
/
EALabels.mod
< prev
next >
Wrap
Text File
|
1995-06-29
|
8KB
|
253 lines
(*************************************************************************
$RCSfile: EALabels.mod $
Description: Text label images for EAGUI.
Created by: fjc (Frank Copeland)
$Revision: 1.2 $
$Author: fjc $
$Date: 1995/06/04 23:20:09 $
Copyright © 1995, Frank Copeland.
This file is part of the Oberon-A Library.
See Oberon-A.doc for conditions of use and distribution.
*************************************************************************)
<* STANDARD- *>
<*$ StackChk- *>
<*$ ReturnChk- *>
<*$ LongVars+ *>
MODULE EALabels;
IMPORT
SYS := SYSTEM, Kernel, s := Sets, e := Exec, u := Utility,
gfx := Graphics, i := Intuition, ea := EAGUI;
CONST
(* Alternative alignment flags. If these aren't specified, the default is
* to center the textfield both horizontally and vertically.
*)
AlignLeft * = 0;
AlignRight * = 1;
AlignTop * = 2;
AlignBottom * = 3;
(* Rendering style flags. If not specified, the text is rendered as
* plain JAM1 text with the default text pen.
*)
ShadowText * = 4; (* Rendered in the default shine pen over an offset
* shadow in the default shadow pen.
*)
TYPE
(* Information that is needed by this object, but that isn't maintained
* by EAGUI itself.
*)
LabelPtr * = POINTER [2] TO Label;
Label * = RECORD [2]
text * : e.LSTRPTR; (* string that is displayed *)
textAttr * : gfx.TextAttrPtr; (* font that is used *)
flags * : s.SET32; (* different flags *)
frontPen *,
backPen * : e.UBYTE; (* pens to use *)
drawMode * : s.SET8; (* draw mode to use *)
END;
VAR
MinSizeHook *, RenderHook * : u.HookPtr;
hook1, hook2 : u.Hook;
itext1, itext2 : i.IntuiText;
(*************************************************************************
* *
* MinSize Method *
* *
*************************************************************************)
PROCEDURE MinSize*
( hook : u.HookPtr;
obj : ea.OPTR;
msg : e.APTR )
: e.ULONG;
VAR
minwidth, minheight, ignore : LONGINT;
lbl : LabelPtr;
BEGIN (* MinSize *)
(* get a pointer to our structure, and check if we actually got it *)
lbl := SYS.VAL (LabelPtr, ea.GetAttr (obj, ea.UserData));
IF lbl # NIL THEN
(* now, we use the library to determine the dimensions of the string *)
minwidth := ea.TextLengthPtr (lbl.textAttr, lbl.text, 0X);
minheight := ea.TextHeightPtr (lbl.textAttr);
IF ShadowText IN lbl.flags THEN
INC (minwidth, 2); INC (minheight)
END;
(* and finally, we set these values *)
ignore := ea.SetAttr (obj, ea.MinWidth, minwidth);
ignore := ea.SetAttr (obj, ea.MinHeight, minheight);
END;
(* we always return success *)
RETURN 0
END MinSize;
(*************************************************************************
* *
* Render Method *
* *
*************************************************************************)
PROCEDURE Render*
( hook : u.HookPtr;
obj : ea.OPTR;
rm : ea.RenderMessagePtr )
: e.ULONG;
VAR
lbl : LabelPtr;
minwidth, minheight, width, height, left, top, ignore : e.ULONG;
BEGIN (* Render *)
(* get a pointer to our structure, and check if we actually got it *)
lbl := SYS.VAL (LabelPtr, ea.GetAttr (obj, ea.UserData));
IF lbl # NIL THEN
(* get sizes of the object *)
ignore := ea.GetAttrs ( obj,
ea.MinWidth, SYS.ADR (minwidth),
ea.MinHeight, SYS.ADR (minheight),
ea.Width, SYS.ADR (width),
ea.Height, SYS.ADR (height),
u.done );
(* get offsets of object relative to root (window) *)
left := ea.GetObjectLeft (rm.root_ptr, obj);
top := ea.GetObjectTop (rm.root_ptr, obj);
(* now align the object *)
IF (AlignRight IN lbl.flags) THEN
INC (left, (width - minwidth));
ELSIF (~(AlignLeft IN lbl.flags)) THEN
INC (left, (width - minwidth) DIV 2);
END;
IF (AlignBottom IN lbl.flags) THEN
INC (top, (height - minheight))
ELSIF (~(AlignTop IN lbl.flags)) THEN
INC (top, (height - minheight) DIV 2);
END;
(* and finally render it *)
IF ShadowText IN lbl.flags THEN
itext1.iTextFont := lbl.textAttr;
itext1.iText := lbl.text;
itext1.frontPen := lbl.backPen;
itext1.drawMode := lbl.drawMode;
itext2.iTextFont := lbl.textAttr;
itext2.iText := lbl.text;
itext2.frontPen := lbl.frontPen;
itext2.drawMode := gfx.jam1;
i.PrintIText (rm.rastport_ptr, itext1, left, top)
ELSE
itext2.iTextFont := lbl.textAttr;
itext2.iText := lbl.text;
itext2.frontPen := lbl.frontPen;
itext1.drawMode := lbl.drawMode;
i.PrintIText (rm.rastport_ptr, itext2, left, top)
END
END;
(* return success *)
RETURN 0
END Render;
(*************************************************************************
* *
* Constructors *
* *
*************************************************************************)
PROCEDURE xNewLabel () : ea.OPTR;
BEGIN (* xNewLabel *)
SYS.SETREG (0,
ea.NewObject ( ea.TYPE_CUSTOMIMAGE,
ea.MinSizeMethod, MinSizeHook,
ea.RenderMethod, RenderHook,
ea.UserData, SYS.REG (8), (* lbl *)
u.more, SYS.REG (9), (* tags *)
u.done ))
END xNewLabel;
PROCEDURE [4] NewLabel* ["EALabels_xNewLabel"]
( VAR lbl [8] : Label;
tags [9].. : u.Tag )
: ea.OPTR;
PROCEDURE [4] NewLabelA* ["EALabels_xNewLabel"]
( VAR lbl [8] : Label;
tags [9] : u.TagListPtr )
: ea.OPTR;
PROCEDURE InitLabel*
( VAR lbl : Label;
text : e.LSTRPTR;
textAttr : gfx.TextAttrPtr;
drawMode : s.SET8;
flags : s.SET32;
drawInfo : i.DrawInfoPtr );
BEGIN (* InitLabel *)
lbl.text := text;
lbl.textAttr := textAttr;
lbl.flags := flags;
lbl.drawMode := drawMode;
IF drawInfo # NIL THEN
IF ShadowText IN flags THEN
lbl.frontPen := SHORT (drawInfo.pens [i.shinePen]);
lbl.backPen := SHORT (drawInfo.pens [i.shadowPen])
ELSE
lbl.frontPen := SHORT (drawInfo.pens [i.textPen]);
lbl.backPen := SHORT (drawInfo.pens [i.backGroundPen])
END
ELSE
IF ShadowText IN flags THEN
lbl.frontPen := 2;
lbl.backPen := 1
ELSE
lbl.frontPen := 1;
lbl.backPen := 0
END
END
END InitLabel;
(************************************************************************)
<*$ LongVars- *>
PROCEDURE Init;
BEGIN (* Init *)
MinSizeHook := SYS.ADR (hook1); RenderHook := SYS.ADR (hook2);
u.InitHook (MinSizeHook, SYS.VAL (u.HookFunc, MinSize));
u.InitHook (RenderHook, SYS.VAL (u.HookFunc, Render));
(* Assuming uninitialised fields are zeroed... *)
itext1.leftEdge := 2; itext1.topEdge := 1;
itext1.frontPen := 1; itext1.drawMode := gfx.jam1;
itext1.nextText := SYS.ADR (itext2);
itext2.frontPen := 2; itext2.drawMode := gfx.jam1
END Init;
BEGIN
Init
END EALabels.